//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#ifndef Green_PyState_H
#define Green_PyState_H

#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "Generator.h"
#include "Scheduler.h"
#include "State.h"
#include "ThreadContext.h"

namespace py = pybind11;

namespace Green {

  PYBIND11_MODULE(State, mod) {
    py::class_<State>(mod, "State")
      .def(py::init([]() {
          ThreadContext thread_context;

          Scheduler* scheduler = Scheduler::Instance();
          Generator* generator = scheduler->LookUpGenerator(thread_context.GetThreadId());
          return new State(generator);
        }))
      .def("addMemoryStateElement", &State::AddMemoryStateElement, py::arg(), py::arg(), py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("addMemoryStateElementsAsBytes", &State::AddMemoryStateElementsAsBytes, py::arg(), py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("addRegisterStateElement", &State::AddRegisterStateElement, py::arg(), py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("addSystemRegisterStateElementByField", &State::AddSystemRegisterStateElementByField, py::arg(), py::arg(), py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("addVmContextStateElement", &State::AddVmContextStateElement, py::arg(), py::arg(), py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("addPrivilegeLevelStateElement",
        [](State& rSelf, const EPrivilegeLevelTypeBaseType privLevelValue, cuint32 priority) {
          rSelf.AddPrivilegeLevelStateElement(EPrivilegeLevelType(privLevelValue), priority);
        },
        py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("addPrivilegeLevelStateElementByName", &State::AddPrivilegeLevelStateElementByName, py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("addPcStateElement", &State::AddPcStateElement, py::arg(), py::arg("aPriority") = 1, py::call_guard<ThreadContext>())
      .def("setDuplicateMode", &State::SetDuplicateMode, py::call_guard<ThreadContext>())
      ;
  }

}

#endif  // Green_PyState_H
